package caat.application.managedbean;

import javax.faces.model.SelectItem;

public class DataTablePaginator {
	private static final SelectItem[] POSITION_AVAILABLE = {
			new SelectItem("bottom", "Bottom"), new SelectItem("top", "Top"),
			new SelectItem("both", "Both") };
	private boolean paginator = true;
	private String position = POSITION_AVAILABLE[0].getValue().toString();
	private int rows = 10;
	private int startPage = 1;

	// ///////////---- GETTERS & SETTERS BEGIN
	public boolean getPaginator() {
		return paginator;
	}

	public String getPosition() {
		return position;
	}

	public int getRows() {
		return rows;
	}

	public int getStartPage() {
		return startPage;
	}

	public SelectItem[] getPositionAvailable() {
		return POSITION_AVAILABLE;
	}

	public int getStartPageMaximum() {
		return (int) Math.ceil(30.0 / (double) rows);
	}

	public void setPaginator(boolean paginator) {
		this.paginator = paginator;
	}

	public void setPosition(String position) {
		this.position = position;
	}

	public void setRows(int rows) {
		this.rows = rows;
		setStartPage(getStartPage());
	}

	public void setStartPage(int startPage) {
		this.startPage = startPage;
		int maxPages = getStartPageMaximum();
		if (this.startPage < 1) {
			this.startPage = 1;
		} else if (startPage > maxPages) {
			this.startPage = maxPages;
		}
	}
}
